package com.luke.web.controller.base;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.luke.common.annotation.Log;
import com.luke.common.core.controller.BaseController;
import com.luke.common.core.domain.AjaxResult;
import com.luke.common.enums.BusinessType;
import com.luke.base.domain.LkConfig;
import com.luke.base.service.ILkConfigService;
import com.luke.common.utils.poi.ExcelUtil;
import com.luke.common.core.page.TableDataInfo;

/**
 * 配置管理Controller
 * 
 * @author luke
 * @date 2021-05-25
 */
@RestController
@RequestMapping("/base/config")
public class LkConfigController extends BaseController
{
    @Autowired
    private ILkConfigService lkConfigService;

    /**
     * 查询配置管理列表
     */
    @PreAuthorize("@ss.hasPermi('base:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(LkConfig lkConfig)
    {
        startPage();
        List<LkConfig> list = lkConfigService.selectLkConfigList(lkConfig);
        return getDataTable(list);
    }

    /**
     * 导出配置管理列表
     */
    @PreAuthorize("@ss.hasPermi('base:config:export')")
    @Log(title = "配置管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LkConfig lkConfig)
    {
        List<LkConfig> list = lkConfigService.selectLkConfigList(lkConfig);
        ExcelUtil<LkConfig> util = new ExcelUtil<LkConfig>(LkConfig.class);
        return util.exportExcel(list, "配置管理数据");
    }

    /**
     * 获取配置管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(lkConfigService.selectLkConfigById(id));
    }

    /**
     * 新增配置管理
     */
    @PreAuthorize("@ss.hasPermi('base:config:add')")
    @Log(title = "配置管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LkConfig lkConfig)
    {
        return toAjax(lkConfigService.insertLkConfig(lkConfig));
    }

    /**
     * 修改配置管理
     */
    @PreAuthorize("@ss.hasPermi('base:config:edit')")
    @Log(title = "配置管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LkConfig lkConfig)
    {
        return toAjax(lkConfigService.updateLkConfig(lkConfig));
    }

    /**
     * 删除配置管理
     */
    @PreAuthorize("@ss.hasPermi('base:config:remove')")
    @Log(title = "配置管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(lkConfigService.deleteLkConfigByIds(ids));
    }
}
